package controller

import (
	"gicechina/help"
	"net/http"
	"strconv"
	"html/template"
)

type Detail struct {
}

//新闻详情
func (c *Detail) NewsDetail(write http.ResponseWriter, r *http.Request) {
	checkGaoLiang(r,write,2)
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "news_detail.html", &TemplateData, "layout", "news_detail", "header", "footer", "right")
}

//活动详情
func (c *Detail) ActiveDetail(write http.ResponseWriter, r *http.Request) {
	checkGaoLiang(r,write,1)
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "active_detail.html", &TemplateData, "layout", "active_detail", "header", "footer", "right")
}

//项目详情
func (c *Detail) ProjectDetail(write http.ResponseWriter, r *http.Request) {
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "project_detail.html", &TemplateData, "layout", "project_detail", "header", "footer", "right")
}
//招聘详情
func (c *Detail) JobDetail(write http.ResponseWriter, r *http.Request) {
	checkGaoLiang(r,write,9)
	getGiceReport()
	getGiceActive()
	help.ParseTemplate(write, "job_detail.html", &TemplateData, "layout", "job_detail", "header", "footer", "right")
}

//判断哪个栏目高亮
func checkGaoLiang(r *http.Request,write http.ResponseWriter,infoType int) {
	TemplateData["indexCurrent"] = ""
	TemplateData["aboutCurrent"] = ""
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = ""
	TemplateData["contactCurrent"] = ""
	nid := r.FormValue("id")
	if nid == "" {
		http.Redirect(write, r, "/", 302)
		return
	}
	nidInt, _ := strconv.Atoi(nid)
	if infoType == 1 {
		NewInfo, err := ActiveModel.GetArticleInfoById(nidInt)
		if err != nil {
			http.Redirect(write, r, "/", 302)
			return
		}
		CateInfo,err := CategoryModel.GetInfoById(NewInfo.CategoryId)
		if err != nil {
			http.Redirect(write, r, "/", 302)
			return
		}
		ActiveModel.AddScanNum(nidInt)
		if NewInfo.CategoryId == 2 {
			TemplateData["activeCurrent"] = "current"
		}
		if NewInfo.CategoryId == 3 {
			TemplateData["projectCurrent"] = "current"
		}
		if NewInfo.CategoryId == 4 {
			TemplateData["videoCurrent"] = "current"
		}
		if NewInfo.CategoryId == 5 {
			TemplateData["newsCurrent"] = "current"
		}
		TemplateData["info"] = NewInfo
		TemplateData["CateInfo"] = CateInfo
		TemplateData["info"] = NewInfo
		var con template.HTML
		con = template.HTML(NewInfo.Content)
		TemplateData["Content"] = con
	} else if infoType == 9 {
		NewInfo, err := JobModel.GetArticleInfoById(nidInt)
		if err != nil {
			http.Redirect(write, r, "/", 302)
			return
		}
		CateInfo,err := CategoryModel.GetInfoById(NewInfo.CategoryId)
		if err != nil {
			http.Redirect(write, r, "/", 302)
			return
		}
		JobModel.AddScanNum(nidInt)
		if NewInfo.CategoryId == 2 {
			TemplateData["activeCurrent"] = "current"
		}
		if NewInfo.CategoryId == 3 {
			TemplateData["projectCurrent"] = "current"
		}
		if NewInfo.CategoryId == 4 {
			TemplateData["videoCurrent"] = "current"
		}
		if NewInfo.CategoryId == 5 {
			TemplateData["newsCurrent"] = "current"
		}
		if NewInfo.CategoryId == 9 {
			TemplateData["jobCurrent"] = "current"
		}
		TemplateData["info"] = NewInfo
		TemplateData["CateInfo"] = CateInfo
		TemplateData["info"] = NewInfo
		var con template.HTML
		con = template.HTML(NewInfo.Content)
		TemplateData["Content"] = con
	} else {
		NewInfo, err := NewsModel.GetArticleInfoById(nidInt)
		if err != nil {
			http.Redirect(write, r, "/", 302)
			return
		}
		CateInfo,err := CategoryModel.GetInfoById(NewInfo.CategoryId)
		if err != nil {
			http.Redirect(write, r, "/", 302)
			return
		}
		NewsModel.AddScanNum(nidInt)
		if NewInfo.CategoryId == 2 {
			TemplateData["activeCurrent"] = "current"
		}
		if NewInfo.CategoryId == 3 {
			TemplateData["projectCurrent"] = "current"
		}
		if NewInfo.CategoryId == 4 {
			TemplateData["videoCurrent"] = "current"
		}
		if NewInfo.CategoryId == 5 {
			TemplateData["newsCurrent"] = "current"
		}
		TemplateData["info"] = NewInfo
		TemplateData["CateInfo"] = CateInfo
		TemplateData["info"] = NewInfo
		var con template.HTML
		con = template.HTML(NewInfo.Content)
		TemplateData["Content"] = con
	}

}
